/**
 * Created by yan_my on 2016/12/9.
 */
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Email{

    private static final String host = "smtp.sina.com";
    private static final String home_address = "xiaoyuqwe@sina.com";
    private static final String password = "123456789";

    public static void sendMail(String target_address){
        Properties props = System.getProperties();
        props.put("mail.smtp.host",host);
        props.put("mail.smtp.auth","true");
        Session session = Session.getDefaultInstance(props, new Authenticator() {
            @Override
            public PasswordAuthentication getPasswordAuthentication(){
                return new PasswordAuthentication(home_address,password);
            }
        });
        try{
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(home_address));
            message.addRecipient(Message.RecipientType.TO,new InternetAddress(target_address));
            message.setSubject("java");
            message.setText("Do you love me?");
            Transport.send(message);
        }catch(MessagingException e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args){Email.sendMail("843901980@qq.com");Email.sendMail("yan_ymy@163.com");}
}